package com.jx.controller.admin.system;

import com.github.pagehelper.PageInfo;
import com.jx.common.result.AjaxResult;
import com.jx.pojo.entity.system.Role;
import com.jx.pojo.vo.system.RoleVO;
import com.jx.service.system.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色 相关接口
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     * 获取列表
     */
    @GetMapping("/listPage")
    public AjaxResult list(RoleVO query) {
        PageInfo<Role> page = roleService.listRole(query);
        return AjaxResult.success(page);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public AjaxResult saveRole(@RequestBody Role role) {
        roleService.saveRole(role);
        return AjaxResult.success("保存成功");
    }

    /**
     * 根据id删除
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam Integer id) {
        roleService.deleteById(id);
        return AjaxResult.success("删除成功");
    }

    /**
     * 根据id获取详情
     */
    @GetMapping("/getById")
    public AjaxResult getById(@RequestParam Integer id) {
        Role role = roleService.getRoleById(id);
        return AjaxResult.success(role);
    }

    /**
     * 修改状态
     */
    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(Integer id, Integer status) {
        roleService.changeStatus(id, status);
        return AjaxResult.success("保存成功");
    }

    /**
     * 获取角色列表
     */
    @GetMapping("/getRoleList")
    public AjaxResult getRoleList() {
        List<Role> list = roleService.getRoleList();
        return AjaxResult.success(list);
    }


}
